# -*- coding: utf-8 -*-
'''
@人民日报
'''

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
from threading import Thread
from config import *
import time

class Browser(object):

    def __init__(self):

        self.options = Options()
        self.options.add_argument('--proxy-server=http://localhost:8080')

        self.options.add_argument('--test-type=--ignore-certificate-errors')
        prefs = {
            'profile.default_content_settings.popups': 0,
            "profile.managed_default_content_settings.images": 1
        }
        self.options.add_experimental_option("prefs", prefs)
        self.options.add_experimental_option('excludeSwitches', ['enable-automation'])  # 专业模式
        self.browser = webdriver.Chrome(options=self.options)

    # 拖动滚动条操作
    def pullScrollOperation(self,num=100):
        # 访问抖音视频网站
        self.browser.get(domain["driver_url"])

        for x in range( num ):

            time.sleep(10)
            # 下拉JS
            scroll = "window.scrollTo(0, document.body.scrollHeight)"

            self.browser.execute_script(scroll)

    # 执行监听程序
    def executeListen(self):
        # 执行监听程序
        CMD = "mitmdump -s mitmProxy.py"

        os.system( CMD )

if __name__ == '__main__':
    b = Browser()

    t1 = Thread( target=b.executeListen,args=()).start()

    t2 = Thread( target=b.pullScrollOperation,args=()).start()



